package com.lyz;

import com.github.benmanes.caffeine.cache.Cache;
import com.github.benmanes.caffeine.cache.Caffeine;

import java.util.concurrent.TimeUnit;

public class CaffeineDemo {
    public static void main(String[] args) {
//        创建缓存实例
        Cache<String, String> caffeine = Caffeine.newBuilder()
                .maximumSize(100)
                .expireAfterWrite(5, TimeUnit.MINUTES)
                .build();
//        存入数据
        caffeine.put("213102","leilei");
//        取出缓存
        String ifPresent = caffeine.getIfPresent("213102");
        System.out.println("取出缓存值："+ifPresent);
//        清除缓存
        caffeine.invalidate("213102");
    }

}
